package com.llb666.e.shop.infrastructure.persistence;

import com.llb666.e.shop.domain.entity.OrderStatus;
import com.llb666.e.shop.domain.repository.OrderStatusRepository;
import com.llb666.e.shop.infrastructure.convert.OrderStatusCvt;
import com.llb666.e.shop.infrastructure.mapper.OrderStatusMapper;
import com.llb666.e.shop.infrastructure.po.OrderStatusPo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * @author 斌~
 * @date 2022/9/12 下午7:13
 */
@Repository
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class OrderStatusRepositoryImpl implements OrderStatusRepository {

    private final OrderStatusMapper orderStatusMapper;

    @Override
    public void updateOrderStatus(String orderId) {
        OrderStatusPo orderStatus = new OrderStatusPo();
        orderStatus.setOrderId(orderId);
        orderStatus.setCommentTime(new Date());
        orderStatusMapper.updateByPrimaryKeySelective(orderStatus);
    }

    @Override
    public void updateOrderStatusByType(String merchantOrderId, Integer orderStatus) {
        OrderStatusPo paidStatus = new OrderStatusPo();
        paidStatus.setOrderId(merchantOrderId);
        paidStatus.setOrderStatus(orderStatus);
        paidStatus.setPayTime(new Date());
        orderStatusMapper.updateByPrimaryKeySelective(paidStatus);
    }

    @Override
    public OrderStatus queryOrderStatusInfo(String orderId) {
        return OrderStatusCvt.INSTANCE.po2do(orderStatusMapper.selectByPrimaryKey(orderId));
    }

    @Override
    public void insert(OrderStatus waitPayOrderStatus) {
        orderStatusMapper.insert(OrderStatusCvt.INSTANCE.do2po(waitPayOrderStatus));
    }

}
